package com.haikesi.api.apcos;

import com.haikesi.api.base.ApiIndex;
import com.haikesi.api.base.R;
import com.haikesi.api.base.annotation.Token;
import com.haikesi.util.ApcosApiUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ApcosApi
 * @Author HandsomeBugs
 * @Date 2019/5/15 15:25
 * @Version 1.0
 **/

@Api(description = "APCOS 万物互联智慧操作系统 平台端接口【测试】", tags = ApiIndex.ApcosApiController)
@RequestMapping(value = "/api/apcosapi")
@RestController
public class ApcosApiController {

    @ApiOperation(value = "得到token")
    @GetMapping(value = "token")
    public R token(
            @ApiParam(value = "第三方唯一标识") @RequestParam String service_id,
            @ApiParam(value = "回调 URI") @RequestParam String call_back_url,
            @ApiParam(value = "唯一标识对应的 key") @RequestParam String service_key) {
        return new R(ApcosApiUtils.getToken(service_id, call_back_url, service_key, true));
    }


    @ApiOperation(value = "订阅账号")
    @GetMapping(value = "subscribe")
    public R subscribe(
            @ApiParam(value = "token") @RequestParam String token,
            @ApiParam(value = "第三方唯一标识") @RequestParam String service_id,
            @ApiParam(value = "被订阅的账号 ") @RequestParam String account) {
        return new R(ApcosApiUtils.subscribe(token, service_id, String.valueOf(System.currentTimeMillis()), account));
    }

    @ApiOperation(value = "获取设备")
    @GetMapping(value = "getDevices")
    public R getDevice(
            @ApiParam(value = "token") @RequestParam String token,
            @ApiParam(value = "第三方唯一标识") @RequestParam String service_id,
            @ApiParam(value = "被订阅的账号 ") @RequestParam String account,
            @ApiParam(value = "获取设备时间 ") @RequestParam Long lastCreatTime
        ) {
        return new R(ApcosApiUtils.getDevice(token, service_id, String.valueOf(System.currentTimeMillis()), account, lastCreatTime));
    }

    @ApiOperation(value = "设备控制")
    @GetMapping(value = "sendDeviceCmd")
    public R sendDeviceCmd(
            @ApiParam(value = "token") @RequestParam String token,
            @ApiParam(value = "第三方唯一标识") @RequestParam String service_id,
            @ApiParam(value = "被订阅的账号 ") @RequestParam String account,
            @ApiParam(value = "序列号[设备序列号和mac 地址一样时是序列号 不一样则是mac地址] ") @RequestParam String serial_num,
            @ApiParam(value = "操作名 ") @RequestParam String operation,
            @ApiParam(value = "操作参数 ") @RequestParam String controlParams,
            @ApiParam(value = "产品编号 ") @RequestParam String productId
    ) {
        return new R(ApcosApiUtils.sendDeviceCmd(token, service_id, String.valueOf(System.currentTimeMillis()), account,serial_num,operation,controlParams,productId));
    }

}
